
	
	var ws = null;
	function setConnected(connected){
		
	}
	
	function connect(){
		
//		var target = document.getElementById('target').value;
//		if(target == ''){
//			alert('select server side');
//			return;
//		}
		
		if('WebSocket' in window){
			ws = new WebSocket('ws://localhost:8090/project-gemloong/myHandler.htm');
			
		} else if ('MozWebSocket' in window){
			ws = new MozWebSocket('ws://localhost:8090/project-gemloong/myHandler.htm');
		} else {
			alert('WebSocket is not supported by this browser');
			return;
		}
		
		ws.onopen = function () {
			console.log('info: websocket connection opened');
		};
		
		ws.onmessage = function(event){
			console.log(event);
		var msg = document.getElementById('text_area_2').value;
		console.log(msg);
		document.getElementById('text_area_2').value = msg + event.data;
			
		};
		
		ws.onclose = function(){
			console.log('closed');
		};
		
		alert('connected!');
	}
	
	function disconnect(){
		if(ws != null) {
			ws.close();
			ws = null;
		}
	}
	
	function echo(){
		if (ws != null){
			var message = document.getElementById('text_area_1').value;
			console.log('Sent: '+message);
		} else {
			alert('websocket connection not established');
		}
		
	}
	
	function updateTarget(target){
		console.log(target);
		console.log(window);
		if(window.location.protocol == 'http:'){
			
			document.getElementById('target').value = 'ws://'+window.location.host+target;
		} else {
			
		}
	}
	
	function sendMsg(){
		if(ws != null){
	        var message = document.getElementById('text_area_1').value;
	        console.log('Send: '+message);
	        ws.send(message);
		} else {
			console.log('WebSocket connection not established, please connect.');
		}
	}
	function connectServer(){

//		var target = document.getElementById('target').value;
//		updateTarget(target);
		connect(); 
	}
	
